package com.rui.patterns.reponsobility;

/**
 * @author : [锐神NO.3]
 * @version : [v1.0]
 * @className : Handler
 * @createTime : [2022/2/24 14:10]
 * @description : [抽象处理者]
 */

public abstract class Handler {

    public final static int NUM_ONE = 1;

    public final static int NUM_THREE = 3;

    public final static int NUM_SEVEN = 7;

    /**
     * 该领导处理的请假天数区间
     */
    private int numStart;
    private int numEnd;

    /**
     * 声明后继者(声明上级领导)
     */
    private Handler nextHandler;

    public Handler(int numStart) {
        this.numStart = numStart;
    }

    public Handler(int numStart, int numEnd) {
        this.numStart = numStart;
        this.numEnd = numEnd;
    }

    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }

    /**
     * 各级领导处理请求条的方法
     */
    protected abstract void handleLeave(LeaveRequest leave);

    /**
     * 提交请假条
     */
    public final void submit(LeaveRequest leave) {
        //该领导先进行审批
        this.handleLeave(leave);
        if(this.nextHandler != null && leave.getNum() > this.numEnd){
            //提交给上级领导审批
            this.nextHandler.submit(leave);
        }else {
            System.out.println("流程结束");
        }
    }
}
